package top.hkyzf.study.leetcode.array;

import org.junit.Test;

import java.util.Arrays;

/**
 * @author 朱峰
 * @date 2022-2-11 9:53
 */
public class 学生分数的最小差值_1984 {
    public int minimumDifference(int[] nums, int k) {
        Arrays.sort(nums);
        int prev = 0;
        int result = Integer.MAX_VALUE;
        for (int next = k-1; next < nums.length; next++) {
            result = Math.min(result, nums[next] - nums[prev]);
            prev++;
        }
        return result;
    }

    @Test
    public void testMinimunDifference () {
        int[] nums = {9,4,1,7};
        int k = 2;
        System.out.println(minimumDifference(nums, k));
    }
}
